﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SQLite.NET;

namespace BierdopjeTV.Database
{

    class GUIEpisodes
    {

        #region Fields

        public int ShowID;
        public int EpisodeID;
        public int Episode;
        public int Season;
        public string Titel;
        public int Wachted;
        public int SubsEN;
        public int SubsNL;
        public string Summary;
        public string AirDate;
        public string Score;
        public string Stemmen;
        public string Source;
        public string Codec;
        public string FileName;
        public string Samenvatting;
        

        #endregion





    }


    static class DBEpisodes
    {

        public static List<GUIEpisodes> getEpisodes(int ShowID, int Season)
        {
            List<GUIEpisodes> _BierdopjeEpisodes = new List<GUIEpisodes>();

            GUIEpisodes _Episode;
            string _Query = "SELECT * FROM LocalEpisodes WHERE ShowID = '" + ShowID.ToString() + "' AND Season = " + Season.ToString() + ";";

            SQLiteResultSet _Result = Helpers.SqliteHelper.ExecuteQuery(_Query);

            for (int i = 0; i < _Result.Rows.Count; i++)
            {
                _Episode = new GUIEpisodes();
                try
                {
                    _Episode.Summary = _Result.Rows[i].fields[(int)_Result.ColumnIndices["Summary"]];
                    _Episode.AirDate = _Result.Rows[i].fields[(int)_Result.ColumnIndices["AirDate"]];
                    _Episode.Score = _Result.Rows[i].fields[(int)_Result.ColumnIndices["Score"]];
                    _Episode.Stemmen = _Result.Rows[i].fields[(int)_Result.ColumnIndices["Votes"]];
                    _Episode.Source = _Result.Rows[i].fields[(int)_Result.ColumnIndices["Source"]];
                    _Episode.Codec = _Result.Rows[i].fields[(int)_Result.ColumnIndices["Codec"]];
                    _Episode.FileName = _Result.Rows[i].fields[(int)_Result.ColumnIndices["Path"]];
                    _Episode.Samenvatting = _Result.Rows[i].fields[(int)_Result.ColumnIndices["Summary"]];               
                  
                _Episode.ShowID = Convert.ToInt32(_Result.Rows[i].fields[(int)_Result.ColumnIndices["ShowID"]]);
                _Episode.EpisodeID = Convert.ToInt32(_Result.Rows[i].fields[(int)_Result.ColumnIndices["EpisodeID"]]);
                _Episode.Season = Convert.ToInt32(_Result.Rows[i].fields[(int)_Result.ColumnIndices["Season"]]);
                _Episode.Episode = Convert.ToInt32(_Result.Rows[i].fields[(int)_Result.ColumnIndices["Episode"]]);
                _Episode.Titel = _Result.Rows[i].fields[(int)_Result.ColumnIndices["Titel"]];                
                _Episode.Wachted = Convert.ToInt32(_Result.Rows[i].fields[(int)_Result.ColumnIndices["Watched"]]);
               

                    //_Episode.SubsEN = Convert.ToInt32(_Result.Rows[i].fields[(int)_Result.ColumnIndices["SubEN"]]);
                    //_Episode.SubsNL = Convert.ToInt32(_Result.Rows[i].fields[(int)_Result.ColumnIndices["SubNL"]]);
                }
                catch (Exception EX)
                {
                    System.Diagnostics.Debug.Print(EX.Message);
                }
        
                
                _BierdopjeEpisodes.Add(_Episode);
                _Episode = null;

            }

            return _BierdopjeEpisodes;

        }
    }
}
